home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
DEMO_VGA
/
FRSTM1.LZH
/
CHKPOINT.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-03-27
|
16KB
|
642 lines
; Malder.asm by Mark C. Peterson, CompuServe [70441,3353]
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT
; int DrawMandelbrot(long it, long jt, int Iter, int RequiredRep,
; long AspectX, long AspectY, int PointsPerLine,
; int ScreenLines, int OverflowMask, int SigDigits,
; int BytesPerLine, Initx, int Inity, int BitInc,
; int OffsetInc, struct _MALSET far *Malset,
; char far *ColorLog, int Buttons, int Direct,
; int InSetMask, int JuliaFlag, long Creal, long Cimag)
; Passed variables
it equ WORD PTR [bp + 6]
jt equ WORD PTR [bp + 10]
Iter equ WORD PTR [bp + 14]
RequiredRep equ WORD PTR [bp + 16]
AspectX equ WORD PTR [bp + 18]
AspectY equ WORD PTR [bp + 22]
PointsPerLine equ WORD PTR [bp + 26]
ScreenLines equ WORD PTR [bp + 28]
OverflowMask equ WORD PTR [bp + 30]
SigDigits equ WORD PTR [bp + 32]
BytesPerLine equ WORD PTR [bp + 34]
Initx equ WORD PTR [bp + 36]
Inity equ WORD PTR [bp + 38]
BitInc equ WORD PTR [bp + 40]
OffsetInc equ WORD PTR [bp + 42]
Mousex equ WORD PTR [bp + 44]
Mousey equ WORD PTR [bp + 46]
Malset equ WORD PTR [bp + 48]
ColorLog equ WORD PTR [bp + 52]
Buttons equ WORD PTR [bp + 56]
Direct equ WORD PTR [bp + 58]
InSetMask equ WORD PTR [bp + 60]
JuliaFlag equ WORD PTR [bp + 62]
Creal equ WORD PTR [bp + 64]
Cimag equ WORD PTR [bp + 68]
; Local variables
temp equ WORD PTR [bp - 8]
sign equ BYTE PTR [bp - 10]
; Pattern recognition variables
Lasti equ WORD PTR [bp - 14]
Lastj equ WORD PTR [bp - 18]
LastRep equ WORD PTR [bp - 20]
NumRep equ WORD PTR [bp - 22]
CheckEvery equ WORD PTR [bp - 24]
LastIter equ WORD PTR [bp - 26]
LowMask equ WORD PTR [bp - 28]
HighMask equ WORD PTR [bp - 30]
; Other local variables
iInit equ WORD PTR [bp - 34]
jInit equ WORD PTR [bp - 38]
Iterations equ WORD PTR [bp - 40]
LinePoints equ WORD PTR [bp - 42]
BitMask equ BYTE PTR [bp - 44]
Offset equ WORD PTR [bp - 46]
Plane equ BYTE PTR [bp - 48]
LastCheck equ WORD PTR [bp - 52]
LastLocal equ 52
; Declared Constants
GraphContPort equ 03ceh
PLANE_SELECT equ 0b2h
PLANE_MASK equ 0e1h
GetATI_REG PROC NEAR
push si
push es
mov ax, 0c000h
mov es, ax
mov si, 10h
mov dx, es:[si]
pop es
pop si
ret
GetATI_REG ENDP
; int GetATIConfig(void)
PUBLIC _GetATIConfig
_GetATIConfig PROC FAR
call GetATI_REG
cli
mov al, 0bbh
out dx, al
inc dx
in al, dx
sti
xor ah, ah
ret
_GetATIConfig ENDP
ATIPlane PROC NEAR ; Plane number in ch
call GetATI_REG
cli
mov al, PLANE_SELECT
out dx, al
inc dl
in al, dx
mov ah, al
and ah, PLANE_MASK
shl ch, 1
or ah, ch
mov al, PLANE_SELECT
dec dl
out dx, ax
sti
ret
ATIPlane ENDP
; void SetATIPlane(int Plane)
extrn _VgaWonder:WORD
PUBLIC _SetATIPlane
_SetATIPlane PROC FAR
push bp
mov bp, sp
mov ax, _VgaWonder
or ax, ax
jz ExitSetATIPlane
mov cx, WORD PTR [bp + 6]
mov ch, cl
call ATIPlane
ExitSetATIPlane:
pop bp
ret
_SetATIPlane ENDP
SetATIPlane PROC NEAR
mov ch, Plane
jmp ATIPlane
SetATIPlane ENDP
; void far _MouseRoutine(int x, int y)
extrn _MouseRoutine:FAR
CheckMouse PROC NEAR
push ax
push bx
push cx
push dx
push si
push di
push es
push ds
mov ax, 3
int 33h
cmp cx, Mousex
jne CallMouse
cmp dx, Mousey
jne CallMouse
cmp bx, Buttons
je ExitCheckMouse
CallMouse:
push dx
push cx
push Malset + 2
push Malset
call _MouseRoutine
call SetATIPlane
pop ax
pop ax
pop Mousex
pop Mousey
ExitCheckMouse:
pop ds
pop es
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
CheckMouse ENDP
SetOffset PROC NEAR
mov ax, Inity ; Calculate initial offset and bit mask
mul BytesPerLine
mov bx, Direct
or bx, bx
jz PlanerOffset
add ax, Initx
mov Offset, ax
jmp ExitSetOffset
PlanerOffset:
mov bx, Initx
mov cx, 3
shr bx, cl
add ax, bx
mov Offset, ax ; Offset = (y * BPL) + (x / 8)
mov cx, Initx
and cl, 7
mov bl, 80h
shr bl, cl ; BitMask = 0x80 >> (x & 7)
mov BitMask, bl
ExitSetOffset:
ret
SetOffset ENDP
NextPixel PROC NEAR
mov cx, BitInc
mov bx, Direct
or bx, bx
jz IncrementBitMask
add Offset, cx
jnc MouseTest
inc Plane
call SetATIPlane
jmp MouseTest
IncrementBitMask:
ror BitMask, 1 ; Setup for next pixel
adc Offset, 0
loop IncrementBitMask
MouseTest:
mov ax, LinePoints
and ax, 03fh
jnz ExitNextPixel
call CheckMouse
ExitNextPixel:
ret
NextPixel ENDP
PUBLIC _DrawMandelbrot
_DrawMandelbrot PROC FAR
push bp
mov bp, sp
sub sp, LastLocal ; Save room on stack for locals
push si
push di
push es
mov ax, 0a000h
mov es, ax
mov Offset, 0
mov BitMask, 80h
mov ax, jt
mov jInit, ax
mov ax, jt + 2
mov jInit + 2, ax
xor ax, ax
mov Plane, al
mov LowMask, ax
mov HighMask, ax
call SetATIPlane
mov cx, SigDigits
add cx, 3 ; Include sign and integer bits
SigDigit:
stc
rcr HighMask, 1
rcr LowMask, 1
loop SigDigit
call SetOffset
LoopY:
mov ax, it
mov iInit, ax
mov ax, it + 2
mov iInit + 2, ax
mov ax, PointsPerLine
mov LinePoints, ax
LoopX:
mov ax, Iter
mov Iterations, ax
mov al, 15
call SetPixel
call CheckPoint ; ax := Color
xor al, 15 ; Remove cursor pixel
call SetPixel
call NextPixel
dec LinePoints ; Next line?
jz CheckLoopY
CheckKey:
mov ah, 1
int 16h
jz IncrementX ; Jump if no keys pressed
cmp al, 27 ; Esc key pressed?
je ExitDrawMandelbrot
mov ah, 0 ; Clear keyboard buffer
int 16h
jmp CheckKey
IncrementX:
mov ax, AspectX
add iInit, ax
mov ax, AspectX + 2
adc iInit + 2, ax
jmp LoopX
CheckLoopY:
mov ax, AspectY
add jInit, ax
mov ax, AspectY + 2
adc jInit + 2, ax
mov ax, OffsetInc
add Offset, ax
jnc CheckScreenLines
inc Plane
call SetATIPlane
CheckScreenLines:
dec ScreenLines ; Done?
jz AllDone
jmp LoopY
AllDone:
xor al, al
ExitDrawMandelbrot:
xor ah, ah
pop es
pop di
pop si
mov sp, bp ; Restore stack pointer
pop bp
ret
_DrawMandelbrot ENDP
SetPixel PROC NEAR
mov dx, Direct
or dx, dx
jz Planer
mov di, Offset
xor BYTE PTR es:[di], al
ret
Planer:
mov ah, al ; Setup color
mov dx, GraphContPort
xor al, al
out dx, ax
mov ax, 0f01h ; Enable reset of all four planes
mov dx, GraphContPort
out dx, ax
mov ax, 1803h ;Set color logic to 'xor'
out dx, ax
mov ah, BitMask ; Set bit mask
mov al, 8
out dx, ax
mov di, Offset ; Write pixel
mov al, es:[di]
mov es:[di], al
mov dx, GraphContPort ; Reset register default values
mov ax, 1
out dx, ax
mov ax, 3
out dx, ax
mov ax, 0ff08h
out dx, ax
ret
SetPixel ENDP
CheckPoint PROC NEAR
xor ax, ax ; Initialize pattern detection locals
mov Lasti, ax ; Lasti := 0
mov Lasti + 2, ax
mov Lastj, ax ; Lastj := 0
mov Lastj + 2, ax
mov NumRep, ax ; NumRep := 0
inc ax
mov LastIter, ax ; LastIter := 1
mov LastRep, ax ; LastRep := 1
inc ax
inc ax
mov CheckEvery, ax ; CheckEver := 3
mov bx, iInit ; Copy initial values to i & j
mov si, iInit + 2
mov cx, jInit
mov di, jInit + 2
mov ax, JuliaFlag
or ax, ax
jnz NextMandelbrotIteration
mov Creal, bx
mov Creal + 2, si
mov Cimag, cx
mov Cimag + 2, di
NextMandelbrotIteration:
mov ax, Iterations
and ax, 1fh
jnz SkipMouseCheck
call CheckMouse
SkipMouseCheck:
call mult16bit ; si:bx := i, di:cx := j
jc MandelbrotOverflow ; Calculate (i * j)
add ax, ax ; dx:ax := 2 * (i * j)
adc dx, dx
add ax, Cimag ; Add Initial j
adc dx, Cimag + 2
push ax ; Save new j
push dx
push di ; Save old j
push cx
mov cx, bx
mov di, si
call mult16bit ; Calculate (i * i)
jc PopFourOverflow
mov LastCheck, ax
mov LastCheck + 2, dx
pop cx ; Get old j
pop di
push dx ; Save (i * i)
push ax
mov bx, cx
mov si, di
call mult16bit ; Calculate (j * j)
jc PopFourOverflow
add LastCheck, ax
adc LastCheck + 2, dx
jo PopFourOverflow
js PopFourOverflow
pop bx ; si:bx := (i * i)
pop si
sub bx, ax ; si:bx := (i * i) - (j * j)
sbb si, dx
add bx, Creal ; Add initial i
adc si, Creal + 2 ; si:bx := New i
pop di ; di:cx := New j
pop cx
jmp CheckForPattern
PopFourOverflow:
pop ax ; Get rid of saved stack stuff
pop ax
PopTwoOverflow:
pop ax
pop ax
MandelbrotOverflow:
push es
mov si, Iter
sub si, Iterations
mov ax, ColorLog + 2
mov es, ax
add si, ColorLog
mov al, BYTE PTR es:[si]
pop es
and ax, OverflowMask
jmp ExitCheckPoint
; **** Pattern recognition algorithm ****
CheckForPattern:
mov ax, LastIter
cmp si, Lasti
jne CheckSampleFreq
cmp di, Lastj
jne CheckSampleFreq
cmp ax, LastRep ; if(LastRep == LastIter)
jne ResetRepetition
mov ax, NumRep ; if(NumRep == RequiredRep)
inc NumRep
cmp ax, RequiredRep
jne DecrementIterations
mov ax, InSetMask ; Set color to number of converged points
or ax, ax
jnz DisplaySet
xor ax, ax
jmp ExitCheckPoint
DisplaySet:
mov ax, Iter
sub ax, Iterations
jmp ExitCheckPoint
ResetRepetition:
mov LastRep, ax ; Repetition frequency didn't match
mov LastIter, 1
jmp DecrementIterations
CheckSampleFreq: ; Need to look at larger samples?
inc LastIter ; if(LastIter++ == CheckEvery) {
cmp ax, CheckEvery
jne DecrementIterations
mov CheckEvery, 1414 ; CheckEvery *= 1.414
mul CheckEvery
mov CheckEvery, 1000
div CheckEvery
mov CheckEvery, ax
mov LastIter, 1 ; Reset last iteration number
mov Lasti, si
mov Lastj, di
mov NumRep, 0 ; Reset number of repetitions
jmp DecrementIterations ; }
; **** End of pattern recognition stuff ****
DecrementIterations:
dec Iterations
jz UnableToDecide
jmp NextMandelbrotIteration
UnableToDecide:
xor ax, ax
jmp ExitCheckPoint
ExitCheckPoint:
ret
CheckPoint ENDP
; Code barrowed from FRACTINT Version 6.1 By Bert Tyler
; my modifications in capitals
mult16bit PROC NEAR
XOR AX, AX
mov temp+4,ax ; first, zero out the (temporary)
mov temp+6,ax ; result
mov sign,al ; clear out the sign flag
OR SI, SI
jns mults1 ; nope
not sign ; yup. flip signs
not bx ; ...
not si ; ...
stc ; ...
adc bx,ax ; ...
adc si,ax ; ...
mults1:
OR DI, DI
jns mults2 ; nope
not sign ; yup. flip signs
not cx ; ...
not di ; ...
stc ; ...
adc cx,ax ; ...
adc di,ax ; ...
mults2:
mov ax,bx ; perform BX x CX
mul cx ; ...
mov temp,ax ; results in lowest 32 bits
mov temp+2,dx ; ...
mov ax,bx ; perform BX x DI
mul di ; ...
add temp+2,ax ; results in middle 32 bits
adc temp+4,dx ; ...
XOR AX, AX
ADC TEMP+6,AX
mov ax,si ; perform SI * CX
mul cx ; ...
add temp+2,ax ; results in middle 32 bits
adc temp+4,dx ; ...
XOR AX, AX
ADC TEMP+6,ax
mov ax,si ; perform SI * DI
mul di ; ...
ADD AX, TEMP+4
ADC DX, TEMP+6
shl temp+2,1
rcl ax,1 ; ...
rcl dx,1 ; ...
jc multovfl ; (oops. overflow)
shl temp+2,1
rcl ax,1 ; ...
rcl dx,1 ; ...
jc multovfl ; (oops. overflow)
shl temp+2,1
rcl ax,1 ; ...
rcl dx,1 ; ...
jc multovfl ; (oops. overflow)
OR DX, DX
jS multovfl ; ...
cmp sign, 0
jZ multnoovfl
not ax ; yup. flip signs.
not dx ; ...
ADD AX, 1
ADC DX, 0
multnoovfl: ; normal exit
clc ; no carry
ret ; we done.
multovfl: ; overflow exit
stc ; set carry
ret ; we done.
mult16bit endp
_TEXT ENDS
END